/*
 * revert_stack.cpp
 * Copyright (C) 2016 libo <libo@tencent.com>
 *
 * Distributed under terms of the MIT license.
 */

#include <iostream>
#include <stack>

using namespace std;

int get_last_one(stack<int>& input) {
  int top = input.top();
  input.pop();
  if (input.size() > 0) {
    int ret = get_last_one(input);
    input.push(top);
    return ret;
  } else {
    return top;
  }
}

int main() {
  stack<int> one_stack;
  one_stack.push(1);
  one_stack.push(2);
  one_stack.push(3);
  one_stack.push(4);
  for (int i = 0; i < (int)one_stack.size(); ++i) {
    one_stack.push(get_last_one(one_stack));
  }
  while(one_stack.size() > 0) {
    cout << one_stack.top() << " ";
    one_stack.pop();
  }
}
